import ElementPlus, {
  ElButton,
  ElSelect,
  ElInfiniteScroll,
  ElLoading,
  ElMessage,
  ElMessageBox,
  ElNotification,
} from 'element-plus';
// 如果要使用.scss样式文件，则需要引入base.scss文件
import 'element-plus/packages/theme-chalk/src/base.scss';
// 组件
const components = [ElButton, ElSelect];
// 插件
const plugins = [ElInfiniteScroll, ElLoading, ElMessage, ElMessageBox, ElNotification];

type Option = {
  size?: 'medium' | 'small' | 'mini';
  zIndex?: number;
  isGlobal?: boolean;
  [propName: string]: any;
};
const plugin: any = {
  install(app: any, { size = 'small', zIndex = 3000, isGlobal = false }: Option = {}): void {
    if (plugin.installed) return;
    app.config.globalProperties.$ELEMENT = { size, zIndex };
    if (!isGlobal) {
      components.forEach(component => app.component(component.name, component));
      plugins.forEach(plugin => app.use(plugin));
    } else {
      app.use(ElementPlus);
    }
  },
};

export default plugin;
export const install = plugin.install;
